{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "09bb72d4",
   "metadata": {},
   "source": [
    "## 2.1 匿名函数与map方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9c97cf78",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_func = lambda x:2*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d6b9a04e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_func(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3101f988",
   "metadata": {},
   "outputs": [],
   "source": [
    "multi_para_func = lambda a, b: a+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c07db912",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "multi_para_func(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8f1bd143",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8, 10, 12, 14]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#匿名函数\n",
    "[(lambda x: 2*x)(i) for i in range(8)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "076ad405",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#map方法映射\n",
    "list(map(lambda x: 2*x, range(5\n",
    "                                )))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dce8890",
   "metadata": {},
   "outputs": [],
   "source": [
    "#追加迭代对象进行函数映射\n",
    "list(map(lambda x, y: str(x)+'_'+y,range(5),list('')))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d8a0398a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#练习\n",
    "name = ['kenny', 'job','jack']\n",
    "age = [15,16,18]\n",
    "\n",
    "#希望得到的效果：['kenny_15','job_16','jack'_18]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d3764867",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['kenny_15', 'job_16', 'jack_18']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#方法\n",
    "list(map(lambda x,y: x+'_'+str(y),name,age))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ba52dad",
   "metadata": {},
   "source": [
    "## 2.3 zip对象与enumerate方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9a60eee2",
   "metadata": {},
   "outputs": [],
   "source": [
    "class1,class2,class3 = list('abc'),list('def'),list('hij')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8c2a8067",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', 'd', 'h'), ('b', 'e', 'i'), ('c', 'f', 'j')]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(zip(class1,class2,class3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c319456b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(('a', 'd', 'h'), ('b', 'e', 'i'), ('c', 'f', 'j'))"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuple(zip(class1,class2,class3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fe3b18d",
   "metadata": {},
   "source": [
    "## 文件的读取和写入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "5ad9e188",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "be76bbb4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "      <th>col5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>a</td>\n",
       "      <td>1.4</td>\n",
       "      <td>apple</td>\n",
       "      <td>2020/1/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>3.4</td>\n",
       "      <td>banana</td>\n",
       "      <td>2020/1/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6</td>\n",
       "      <td>c</td>\n",
       "      <td>2.5</td>\n",
       "      <td>orange</td>\n",
       "      <td>2020/1/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>d</td>\n",
       "      <td>3.2</td>\n",
       "      <td>lemon</td>\n",
       "      <td>2020/1/7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col1 col2  col3    col4      col5\n",
       "0     2    a   1.4   apple  2020/1/1\n",
       "1     3    b   3.4  banana  2020/1/2\n",
       "2     6    c   2.5  orange  2020/1/5\n",
       "3     5    d   3.2   lemon  2020/1/7"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('D:/data_analysis-master/data/my_csv.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b054a4ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.read_table('')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
